package org.biliviz.be.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.biliviz.be.entity.AuthorInfo;
import org.biliviz.be.entity.VtChannelCount;
import org.biliviz.be.entity.vo.ChannelCount;
import org.biliviz.be.mapper.VtChannelCountMapper;
import org.biliviz.be.service.VtChannelCountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sg
 * @since 2024-02-20
 */
@Service
public class VtChannelCountServiceImpl extends ServiceImpl<VtChannelCountMapper, VtChannelCount> implements VtChannelCountService {
    @Override
    public List<VtChannelCount> getAll() {
        QueryWrapper<VtChannelCount> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("is_sub", false)
                .eq("is_top", false);

        List<VtChannelCount> channelCount = baseMapper.selectList(queryWrapper);
        return channelCount;
    }

    @Override
    public List<VtChannelCount> getTop100() {
        QueryWrapper<VtChannelCount> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("is_sub", false)
                .eq("is_top", true);
        List<VtChannelCount> channelCount = baseMapper.selectList(queryWrapper);
        return channelCount;
    }

    @Override
    public List<ChannelCount> getChannelCC(String channel) {
        QueryWrapper<VtChannelCount> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("channel",channel)
                .eq("is_sub", true)
                .eq("is_top", false);

        List<VtChannelCount> subChannel = baseMapper.selectList(queryWrapper);
        List<ChannelCount> channelCounts = new ArrayList<>();

        for (VtChannelCount vtChannelCount : subChannel ) {
            ChannelCount channelCount = new ChannelCount();
            channelCount.setChannel(vtChannelCount.getSubChannel());
            channelCount.setCount(vtChannelCount.getCount());
            channelCounts.add(channelCount);
        }
        return channelCounts;
    }
}
